<template>
  <div class="dialog" v-show="showMask">
    <div class="dialog-container">
      <div class="btns">
        <div class="title">{{ timerList.title }}</div>
        <div class="btnContainer">
          <div
            class="timerBtnContainer"
            v-for="(item, key) in timerList.list"
            :key="key"
            @click="clickItem(key)"
          >
            <div class="timeBtn">
              <div class="left">{{ item.name }}</div>
              <div class="center">
                {{ getDefaultText(key) }}
              </div>
              <img class="right" :src="getSelectImg(key)" />
            </div>
            <div class="divider"></div>
          </div>
        </div>
        <div class="cancelContainer" @click="clickCancel">
          <div class="cancel">{{ cancelText }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    show: {
      type: Boolean,
      defalut: false,
    },
    selectRoomIndex: {
      type: Number,
      default: 0,
    },
    timerList: {},

    cancelText: {
      type: String,
      default: "取消",
    },

    bottom: {
      type: Number,
      default: 405,
    },
  },
  data() {
    return {
      showMask: false,
      selectIndex: 0,
    };
  },
  computed: {},
  methods: {
    closeMask() {
      this.showMask = false;
      this.$emit("update:show", false);
    },
    clickItem(key) {
      this.$emit("update:selectRoomIndex", key);
      this.closeMask();
    },
    clickCancel() {
      this.$emit("cancel");
      this.closeMask();
    },
    getSelectImg: function (key) {
      if (this.timerList.selectedIndex == key) {
        return require("../../assets/img/ic_list_ratio_on.png");
      } else {
        return require("../../assets/img/ic_list_ratio_off.png");
      }
    },
    getDefaultText: function (key) {
      if (this.timerList.defaultSet == key) {
        return ""; //"(默认定时)";
      } else {
        return "";
      }
    },
  },
  mounted() {
    this.showMask = this.show;
    if (this.selectRoomIndex < 0) {
      this.selectIndex = 0;
    } else {
      this.selectIndex = this.selectRoomIndex;
    }
  },
  watch: {
    show(newVal, oldVal) {
      this.showMask = newVal;
    },
    selectRoomIndex(newVal, oldVal) {
      if (newVal < 0) {
        this.selectIndex = 0;
      } else {
        this.selectIndex = newVal;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.dialog {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9999;
  .dialog-container {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    // .btnsShow {
    //   transform: translateY(0%);
    // }
    .btns {
      border-radius: 16px;
      box-shadow: 0px 8px 18px rgba(0, 0, 0, 0.25);
      width: 100%-6px;
      height: 312px;
      display: flex;
      flex-direction: column;
      margin-bottom: 10px;
      background: rgba(255, 255, 255, 1);
      // transition: all 0.3s ease;
      // transform: translateY(20%);
      .title {
        font-size: 20px;
        color: rgba(0, 0, 0, 1);
        margin-top: 25px;
        margin-left: 19px;
        margin-bottom: 12px;
      }
      .btnContainer {
        height: 100px;
        width: 100%;
        overflow-y: scroll;
        overflow-x: hidden;
        flex-direction: column;
        display: flex;
        .timerBtnContainer {
          display: flex;
          flex-direction: column;
          height: 48px;
          width: 100%;
          .timeBtn {
            flex: 1;
            width: 100%;
            background: rgba(255, 255, 255, 1);
            &:active {
              background: rgba(0, 0, 0, 0.05);
            }
            display: flex;
            flex-direction: row;
            align-items: center;
            .left {
              font-size: 16px;
              color: black;
              margin-left: 22px;
            }
            .center {
              flex: 1;
              font-size: 12px;
              color: rgba(0, 0, 0, 0.4);
              padding-left: 12px;
            }
            .right {
              width: 24px;
              height: 24px;
              margin-right: 12px;
            }
          }
          .divider {
            width: 100%;
            height: 1px;
            margin-left: 11px;
            margin-right: 13px;
            background-color: rgba(151, 151, 151, 0.05);
          }
        }
      }
      .cancelContainer {
        display: flex;
        flex-direction: row;
        justify-content: center;

        .cancel {
          font-size: 16px;
          color: #0a59f7;
          background: chocolate;
        }
      }
    }
  }
}
</style>
